import java.sql.*;
import javax.sql.*;

public class DBTest{

public static void main(String args[]){
String col1Val;
String col2Val;

//MySQL
//String dbUrl = "jdbc:mysql://localhost:3306/mydb?";
//String dbClass = "com.mysql.jdbc.Driver";

//PostGres
String dbUrl = "jdbc:postgresql://localhost:5432/postgres?";

String query = "Select * FROM department";

try {

//Class.forName("com.mysql.jdbc.Driver");
Class.forName("org.postgresql.Driver");
	
//Connection con = DriverManager.getConnection (dbUrl,"root","pass");
Connection con = DriverManager.getConnection (dbUrl,"postgres","pass");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

while (rs.next()) {
 col1Val= rs.getString(1);
 col2Val= rs.getString(2);
System.out.println(col1Val);
System.out.println(col2Val);
} //end while

con.close();
} //end try

catch(ClassNotFoundException e) {
e.printStackTrace();
}

catch(SQLException e) {
e.printStackTrace();
}

}  //end main

}  //end class
